package com.sl.core.engine.plugin;

import cn.hutool.core.util.ClassLoaderUtil;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ReflectUtil;
import org.apache.hop.core.plugins.IClassLoadingPlugin;
import org.apache.hop.core.plugins.IPluginType;
import org.apache.hop.core.plugins.Plugin;

import java.net.URL;
import java.util.List;
import java.util.Map;

public class ProcessSupplementalPlugin extends Plugin implements IClassLoadingPlugin {

    private Class<?> clazz;

    public ProcessSupplementalPlugin(
            String[] ids,
            Class<? extends IPluginType> pluginType,
            Class<?> mainType,
            String category,
            String name,
            String description,
            String imageFile,
            boolean separateClassLoaderNeeded,
            boolean nativePlugin,
            Map<Class<?>, String> classMap,
            List<String> libraries,
            String errorHelpFile,
            String[] keywords,
            URL pluginFolder,
            boolean usingLibrariesOutsidePluginFolder, Class<?> clazz) {
        super(ids,pluginType,mainType,category,name,description,imageFile,separateClassLoaderNeeded,
                nativePlugin,classMap,libraries,errorHelpFile,keywords,pluginFolder,usingLibrariesOutsidePluginFolder);
        this.clazz = clazz;
    }
    @Override
    public <T> T loadClass(Class<T> pluginClass) {
//        Class<?> objectClass = ClassLoaderUtil.loadClass(pluginClass.getName(), clazz.getClassLoader(), true);
        return (T) ReflectUtil.newInstance(clazz);
    }

    @Override
    public ClassLoader getClassLoader() {
        return clazz.getClassLoader();
    }
}
